package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.entity.Category;
import com.shop.entity.Product;
import com.shop.service.CategoryService;
import com.shop.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * description: 该文件说明
 *
 * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
 * @version 1.0
 * @date 2018/10/17 15:47
 **/
@Controller
@RequestMapping("/sellerProduct")
public class SellerProductController {

    @Resource
    private ProductService productService;
    @Resource
    private CategoryService categoryService;
    /**
     * description:<通过类目查找商品>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/17 17:02
     * @param  
     * @return 
     **/
    @RequestMapping("/findProduct")
    public ModelAndView showProduc(@RequestParam(value = "page",defaultValue = "1") Integer page,@RequestParam(value = "row",defaultValue = "4") Integer row,Product product){
        ModelAndView model = new ModelAndView("list");
        PageInfo<Product> pageInfo = productService.findProductByCategoryType(page,row,product);
        List<Category> categoryList = categoryService.findCategoryAll();
        model.addObject("categoryList",categoryList);
        model.addObject("product",product);
        model.addObject("pageInfo",pageInfo);
        return model;
    }
    /**
     * description:<商品详情>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/17 17:02
     * @param
     * @return
     **/
    @RequestMapping("/findProductByProductId")
    public ModelAndView findProductByProductId( String  productId){
        ModelAndView model = new ModelAndView("productDetail");
        List<Category> categoryList = categoryService.findCategoryAll();
        Product product = productService.findProductByProductId(productId);
        model.addObject("categoryList",categoryList);
        model.addObject("product",product);
        return model;
    }

}
